<?php
if (!defined('APP') or !constant('APP')) die('Direct access not allowed!');

class UserHistoryModel
{
    public static function save($data)
    {
        $query = "INSERT INTO `users_history` (`id_user`, `controller`, `action`, `ip`)
                        VALUES (:id_user, :controller , :action , :ip );";
        
        $data[':id_user'] = intval(UserModel::isLoggedIn());
        $data[':ip'] = System::getRealIpAddr();
       
        $result = DB::getPDO()->prepare($query);
        $r = $result->execute($data);      
    }
    
    public static function fetchAll()
    {
        $query = "SELECT * FROM `users_history` uh, `users` u  WHERE `uh`.`id_user` = `u`.`id` ";
        $result = DB::getPDO()->prepare($query);
        $result->execute();  
        $result = $result->fetchAll();       
        return $result;
    }
}

?>
